package com.xcc.java_juc;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 显示锁
 */
public class Demo01_ReentrantLockShow {

    static Lock lock = new ReentrantLock();

    public static void main(String[] args) {
        new Thread(()->{
            lock.lock();
            try {
                System.out.println(Thread.currentThread().getName() + "==============外部");
                lock.lock();
                try {
                    System.out.println(Thread.currentThread().getName() + "==============内部");
                }finally {
                    lock.unlock();
                }
            }finally {
                lock.unlock();
//                lock.unlock();
            }

        },"t1").start();

        new Thread(()->{
            lock.lock();
            try {
                System.out.println(Thread.currentThread().getName() + "==========进入方法");
            }finally {
                lock.unlock();
            }
        },"t2").start();
    }

}
